package ru.amse.tsyganov.jumleditor.commands;

import java.util.ArrayList;
import java.util.List;

/*package*/ class CompositeCommand extends Command {
	
	private final ArrayList<? extends Command> commandList;
	
	public CompositeCommand(List<? extends Command> commandList) {
		if (commandList == null || commandList.size() == 0) {
			throw new IllegalArgumentException();
		}
		this.commandList = new ArrayList<Command>(commandList);
	}
	
	@Override
	public void execute() {
		for (Command c : commandList) {
			c.execute();
		}
	}

	@Override
	public void unexecute() {
		for (int i = commandList.size() - 1; i >= 0; i--) {
			commandList.get(i).unexecute();
		}
	}

}
